package com.nlscan.ncomgateway.core.data.preference

import com.nlscan.ble.util.NSpUtil
import com.nlscan.qdkit.common.core.app.App

/**
 * <pre>
 *  author: lin.qing
 *  time  : 2023/4/6
 *  desc  :
 * </pre>
 */
object GeneralPreferenceManager {

    private const val SP_NAME = "sp_general"

    private const val KEY_SELECT_LAUNCH_PKG_NAME = "key_select_launch_pkg_name"
    private const val KEY_DATA_PACKAGE_ENABLE = "key_data_package_enable"
    private const val KEY_HEX_SEND_ENABLE = "key_hex_send_enable"

    private var spUtil: NSpUtil? = null

    fun getInstance(): GeneralPreferenceManager {

        if (spUtil == null) {
            spUtil = NSpUtil(App.getInstance(), SP_NAME)
        }
        return this
    }

    fun getSelectLaunchPkgName(): String {

        return getSpUtil().getString(KEY_SELECT_LAUNCH_PKG_NAME, "")
    }

    fun setSelectLaunchPkgName(name: String) {
        getSpUtil().putString(KEY_SELECT_LAUNCH_PKG_NAME, name)
    }

    fun isDataPackage(): Boolean =
        getSpUtil().getBoolean(KEY_DATA_PACKAGE_ENABLE, true)

    fun setDataPackage(enable: Boolean) =
        getSpUtil().putBoolean(KEY_DATA_PACKAGE_ENABLE, enable)

    fun isHexSend(): Boolean =
        getSpUtil().getBoolean(KEY_HEX_SEND_ENABLE, false)

    fun setHexSend(enable: Boolean) =
        getSpUtil().putBoolean(KEY_HEX_SEND_ENABLE, enable)

    private fun getSpUtil(): NSpUtil {
        if (spUtil == null) {
            spUtil = NSpUtil(App.getInstance(), SP_NAME)
        }
        return spUtil!!
    }


}